package com.cn.hangyun.service.impl;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.hangyun.common.DateUtil;
import com.cn.hangyun.dao.Rt_pull_controlMapper;
import com.cn.hangyun.dao.Rt_pull_dataMapper;
import com.cn.hangyun.dao.Rt_pull_transducerMapper;
import com.cn.hangyun.model.Rt_pull_control;
import com.cn.hangyun.model.Rt_pull_transducer;
import com.cn.hangyun.model.requestVO.PullRequestBean;
import com.cn.hangyun.service.IPullService;

@Service("pullService")
public class PullServiceImpl implements IPullService{
	
	@Autowired
	private Rt_pull_transducerMapper pullTranMapper;
	
	@Autowired
	private Rt_pull_controlMapper pullContMapper;
	
	@Autowired
	private Rt_pull_dataMapper pullDataMapper;

	@Override
	public Rt_pull_control getLastPullControl(Date current) {
		Rt_pull_control data = pullContMapper.selectLast(current);
		return data;
	}

	@Override
	public List<Rt_pull_transducer> getAllPullTran() {
		List<Rt_pull_transducer> list = pullTranMapper.selectAll();
		return list;
	}

	@Override
	public Map<String, List<String>> getPullData(PullRequestBean bean) {
		
		String controlId = bean.getControlId();
		Date start = bean.getStart();
	    Date end = DateUtil.getEndTime(start, bean.getInterval());
		
		String tran1 = bean.getTran1();
		String tran2 = bean.getTran2();
		String tran3 = bean.getTran3();
		
		List<String> data1 = pullDataMapper.selectData(controlId, start, end, bean.getTran1());	
		List<String> data2 = pullDataMapper.selectData(controlId, start, end, bean.getTran2());	
		List<String> data3 = pullDataMapper.selectData(controlId, start, end, bean.getTran3());	

		Map<String, List<String>> map = new LinkedHashMap<String, List<String>>();
		map.put(tran1, data1);
		map.put(tran2, data2);
		map.put(tran3, data3);
		
		return map;
	}
}
